<template>
  <div class="container">
    <subject-table
      xxx-xx="123"
      title="helloVue"
      :list="list"
      @delByIndex="delByIndexFn"
    ></subject-table>
    <subject-t-able :list="list" @delByIndex="delByIndexFn"></subject-t-able>
    <add-form @submit="onSubmit"></add-form>
  </div>
</template>

<script>
import AddForm from "./components/AddForm.vue";
import SubjectTAble from "./components/SubjectTable.vue";

export default {
  components: { SubjectTAble, AddForm },
  name: "App",
  data() {
    return {
      list: [
        {
          id: 100,
          subject: "语文",
          score: 99,
          time: new Date("2010-08-12"),
        },
        {
          id: 101,
          subject: "数学",
          score: 34,
          time: new Date("2020-09-01"),
        },
        {
          id: 102,
          subject: "英语",
          score: 25,
          time: new Date("2018-11-22"),
        },
        {
          id: 103,
          subject: "体育",
          score: 100,
          time: new Date("2020-12-12"),
        },
      ],
    };
  },
  methods: {
    delByIndexFn(index) {
      console.log("index  ----->  ", index);
      this.list.splice(index, 1);
    },
    // 2.3. 父组件, 通过push添加新数据
    onSubmit(subject, score) {
      const newItem = {
        subject,
        score,
        id: Date.now(),
        time: new Date(),
      };
      this.list.push(newItem);
    },
  },
};
</script>

<style scoped></style>
